# -*- coding: utf-8 -*-

import scrapy

class IndexSpider(scrapy.Spider):
    name = "vxinghe"
    start_urls = [
        'http://vxinghe.com/',
    ]
    # def start_requests(self):
    #     return [scrapy.FormRequest("http://www.vxinghe.com/",
    #                                formdata={'user': 'john', 'pass': 'secret'},
    #                                callback=self.logged_in)]
    # def logged_in(self, response):
    #     print("哈哈哈哈哈哈")

    def parse(self, response):
        basePath = "div.model1-content"
        titlePath = "div.model1-title a::text"
        descPath = "div.model1-desc::text"
        fromPath = "span.special-from::text"
        for quote in response.css(basePath):
            item = {
                'title': quote.css(titlePath).extract_first(),
                'desc': quote.css(descPath).extract_first(),
                'from1': quote.css(fromPath).extract_first()
            }
            yield item
            str = quote.css(titlePath).extract_first()
            print(str.encode('utf-8'))
            print(">>>>>>>>>>>>>", type(item))

        next_page_url = response.css("li.next > a::attr(href)").extract_first()
        if next_page_url is not None:
            yield scrapy.Request(response.urljoin(next_page_url))

